<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-03-28
 * Time: 下午 4:39
 */
namespace Model;
class ActivityTreasureMod extends Mod
{
	public function __construct()
	{
		$this->_table = 'kuyuan_vbz_activity_treasure';
	}

	/**
	 * 返回活动可生成的宝藏
	 * @param $_activity_id 活动id
	 * @param $_type
	 */
	public function getBz($_activity_id,$_type)
	{
		$_sql = "SELECT
						id,win_odds,user_number,type,icon,name,money
					FROM
						".tablename($this->_table)."
					WHERE
						activity_id = :activity
					AND
						give_number < number
					 AND
					 	type = :type
					 AND
					    status = 1
					ORDER BY 
						win_odds DESC	
				";
		return pdo_fetchall($_sql,array('activity'=>$_activity_id,'type'=>$_type));
	}


	/**
	 * 获取要删除的宝藏id
	 * @param $_activity_id
	 * @param $_type
	 * @param array $_ids
	 * @return mixed
	 */
	public function findDeleteTreasure($_activity_id,$_type,Array $_ids)
	{
		$_not_ids = '';
		foreach($_ids as $_v){
			$_not_ids .= $_v.',';
		}
		$_not_ids = substr($_not_ids,0,-1);
		$_sql = "
				SELECT 
						id
				FROM
					".tablename($this->_table)."
				WHERE
					activity_id = :activity_id
				AND
					type = :type
				AND
					status = 1
				AND
					id NOT IN($_not_ids)
				";
		return pdo_fetchall($_sql,array('activity_id'=>$_activity_id,'type'=>$_type));
	}

}